import absanimateengine from "./absanimateengine";
import lgxcom from '../common/common'
class TransformEngine extends absanimateengine.AbsAnimateEngine {
    constructor(graph) {
        super(graph);
        this.type = "transform";
        this.orginLenth = -1;
        this.dir = new lgxcom.LGXVector();
        this.dir.m = 1;
        this.dir.n = 0;
    }
    
    animate() {
        console.log("animate transform -------------------");
        let position = this.destGraph.getPos();
        if (this.orginLenth < 0){
            this.orginLenth = position.radius;
        }
        
        position.radius = position.radius+this.speed;
        this.destGraph.calScope(1);
        if (position.radius  > this.orginLenth*2){
            this.speed = -2;
        }
        else if (position.radius  < this.orginLenth*0.2){
            this.speed = 2;
        }
    }

    animate_polypos() {
        console.log("animate transform -------------------");
        if (this.orginLenth < 0){
            this.orginLenth = this.destGraph.getZone().width();
        }
        let position = this.destGraph.getPos();
        let p1 = position.posList[1];
        p1.x = p1.x + this.speed*this.dir.m;
        p1.y = p1.y + this.speed*this.dir.n;

        let p2 = position.posList[2];
        p2.x = p2.x + this.speed*this.dir.m;
        p2.y = p2.y + this.speed*this.dir.n;
        this.destGraph.calScope(1);
        let newLen = this.destGraph.getZone().width();
        if (newLen > this.orginLenth*2){
            this.speed = -2;
        }
        else if (newLen < this.orginLenth*0.2){
            this.speed = 2;
        }
    }
}

export default { TransformEngine }